package com.tzg157.fitness.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@NoArgsConstructor
public class R<T> implements Serializable {

    private Integer code;
    private String msg;
    private T data;

    private static final int OK = 0;

    public R(Integer code, String msg, T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T>R<T> ok(T data){
        return new R<>(OK, "OK", data);
    }

    public static <T> R<T> error(){
        return new R<>(500, "error", null);
    }

    public static <T> R<T> error(String msg){
        return new R<>(500, msg, null);
    }
}
